$(document).ready(function () {
    init()
})

var $link = $(".left-nav").find('a');
var $username
var $password
var $userid
var user
var $userimage


function init() {
    $.ajax({
        url:url+"getSession.do",
        type:"get",
        data:"",
        datatype:"json",
        success:function (data) {
            var data=JSON.parse(data);
            if(data.result=="success")
            {
                user=data.user;
                $username=user.username;
                $password=user.password;
                $userid = user.id;
                $userimage=user.imagesrc;
                console.log($userimage)
                $("#userpicture").attr("src",$userimage);
                $("#myname").text($username)
                $(".content").html("<h2><b>欢迎用户:"+$username+"</b></h2>")
                initMenu($username);
            }
        }
    })
}
//init

function initMenu(username) {
    $.ajax({
        url:url+"/person/getMyRoom.do",
        data:{username:username},
        type:"get",
        datatype:"json",
        success:function(data)
        {
            console.log(data)
            if(data!="null")
            {
                $("a[name='master']").removeClass('hide');
            }
            else
            {
                $("a[name='person']").removeClass('hide');
            }
        }
    })
}
//do
function getRootPath() {
    //获得根目录
    var strFullPath = window.document.location.href;
    var strPath = window.document.location.pathname;
    var pos = strFullPath.indexOf(strPath);
    var prePath = strFullPath.substring(0, pos);
    var postPath = strPath.substring(0, strPath.substr(1).indexOf('/') + 1);
    return (prePath + postPath);
}
function LoadHtml(name) {
    var path=getRootPath();
    var url = path+"/project"+"/view/"+name+".html";
    $('.content').load(url);
}

$link.on('click',function () {
    var result= $(this).attr("data");

    if(result == "information")
    {
        LoadHtml("personalInfo");
    }
    else if(result=="follow")
    {
        LoadHtml("personfollow")
    }
    else if(result == "password")
    {
        LoadHtml("resetpassword")
    }
    else if(result=="applyLive")
    {
        LoadHtml("applyLive");
    }
    else  if (result =="myroom")
    {
        LoadHtml("myroom");
    }else if(result=="myvideo")
    {
        LoadHtml("myvideo");
    }
    else
    {
        LoadHtml("error");
    }
})

